package com.example.logutil;

import com.example.logutil.common.LogLevel;
import com.example.logutil.common.LogType;
import com.example.logutil.impl.Consolelmpl;
import com.example.logutil.impl.Logcatlmpl;

public class Logger {

    private ILogger logger;

    private Logger(boolean isDebug,String tag,LogLevel level,LogType logType){
        switch (logType){
            case LOGCAT:
                logger = new Logcatlmpl();
                break;
            case CONSOLE:
                logger = new Consolelmpl();
                break;
            case EMAIL:
            case SERVER:
            case DB:
            default:
                logger = new Logcatlmpl();
        }
        logger.isDebug(isDebug);
        logger.setTag(tag);
        logger.setLevel(level);
    }

    public void i(String subTag,String log){
        logger.i(subTag,log);
    }

    public void d(String subTag,String log){
        logger.d(subTag,log);
    }

    public void w(String subTag,String log){
        logger.w(subTag,log);
    }

    public void e(String subTag,String log){
        logger.e(subTag,log);
    }


    public static class Builder{

        private boolean isDebug = false;
        private String tag = "";
        private LogLevel level = LogLevel.INFO;
        private LogType logType = LogType.LOGCAT;

        public Builder setDebug(boolean debug) {
            isDebug = debug;
            return this;
        }

        public Builder setTag(String tag) {
            this.tag = tag;
            return this;
        }

        public Builder setLevel(LogLevel level) {
            this.level = level;
            return this;
        }

        public Builder setLogType(LogType logType) {
            this.logType = logType;
            return  this;
        }

        public Logger build(){
            return new Logger(this.isDebug,this.tag,this.level,this.logType);
        }
    }
}
